<template>
  <div class="app-container">
    <!-- 表格 -->
    <el-table
      :key="tableKey"
      ref="table"
      v-loading="listLoading"
      :data="list"
      :border="false"
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="拍品" header-align="center">
        <template slot-scope="{ row }">
          <div v-if="row.order">订单编号：{{ row.order.order_no }}</div>
          <el-image
            v-if="row.product"
            style="width: 40px; height: 40px; text-align: center"
            :src="$store.state.settings.imgHost + row.product.image"
            :preview-src-list="[
              $store.state.settings.imgHost + row.product.image,
            ]"
          />
          <span
            v-if="row.product"
            style="vertical-align: top; margin-left: 10px"
          >{{ row.product.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="起拍价/成交价" align="center">
        <template slot-scope="{ row }">
          {{ row.start_price }}/{{ row.end_price }}
        </template>
      </el-table-column>
      <el-table-column label="实付款" prop="actual_money" align="center" />
      <el-table-column label="买家" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.buyer">{{ row.buyer.name }}</div>
          <div v-if="row.buyer">{{ row.buyer.mobile }}</div>
        </template>
      </el-table-column>
      <el-table-column label="订单状态/时间" width="200" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.order">
            {{
              row.order.order_type == 0
                ? "待支付"
                : row.order.order_type == 1
                  ? "待发货"
                  : row.order.order_type == 2
                    ? "待收货"
                    : row.order.order_type == 3
                      ? "已完成"
                      : row.order.order_type == 9
                        ? "已成交(完成)"
                        : row.order.order_type == 10
                          ? "退款完成"
                          : row.order.order_type == 11
                            ? "退货"
                            : row.order.order_type == 12
                              ? "退货中"
                              : ""
            }}
          </div>
          <div v-if="row.order">{{ row.order.created_at }}</div>
        </template>
      </el-table-column>
      <el-table-column label="推荐人" width="240px">
        <template slot-scope="{ row }">
          <div v-if="row.recommend">
            一级分销：{{ row.recommend.name }} 佣金：{{ row.commission_price }}
          </div>
          <div v-if="row.second_recommend">
            二级分销：{{ row.second_recommend.name }} 佣金：{{
              row.second_commission_price
            }}
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button
            size="mini"
            plain
            type="primary"
            @click="handleLook(row.order_id)"
          >
            查看订单详情
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <!-- 分页 -->
    <div v-if="total > 0" style="text-align: right">
      <pagination
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.per_page"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { getRecommendorders, deleteArt } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'DistributionsManageOrders',
  components: {
    Pagination
  },
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      type: 0,
      listQuery: {
        page: 1,
        per_page: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleLook(id) {
      this.$router.push('/distributions-manage/detail-fx/' + id)
    },
    getList() {
      this.listLoading = true
      getRecommendorders(this.listQuery)
        .then((response) => {
          const { data, total } = response.data
          this.list = data
          this.total = total
        })
        .finally(() => {
          this.listLoading = false
        })
    },
    // 禁用
    handleDisables(id) {
      this.$confirm(
        '您确认禁用当前商户吗？禁用后，商户拍品将全部为待拍商品，商户列表中不显示当前商户',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {})
        .catch(() => {})
    }
  }
}
</script>
